package com.neusoft.yuejian_01.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.neusoft.yuejian_01.activity.TrainDetailActivity;
import com.neusoft.yuejian_01.R;
import com.neusoft.yuejian_01.base.BaseAdapter;
import com.neusoft.yuejian_01.javabean.TrainBean;
import com.neusoft.yuejian_01.model.ConstPhoto;
import com.neusoft.yuejian_01.viewHolder.TrainViewHolder;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by Administrator on 2017/10/2.
 */

public class TrainAdapter extends BaseAdapter {
    public TrainAdapter(Context context, List data) {
        super(context, data);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateVH(ViewGroup parent, LayoutInflater layoutInflater, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_trainlist, parent, false);
        TrainViewHolder viewHolder = new TrainViewHolder(itemView);
        return viewHolder;
    }

    @Override
    protected void onBindVH(RecyclerView.ViewHolder holder, List data, int position) {
        TrainBean trainlist = (TrainBean) data.get(position);
        TrainViewHolder viewHolder = (TrainViewHolder) holder;
        String trainName = trainlist.getT_name();
        final int t_id = trainlist.getT_id();
        viewHolder.trainView.setText(trainName);
        String trainImage = ConstPhoto.BASE_URL+ConstPhoto.TrainFile+trainlist.getT_picture();
        Picasso.with(context)
                .load(trainImage)
                .placeholder(R.drawable.pic2)
                .into(viewHolder.trainImage);
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //启动新的activity(培训详情)
                Intent intent = new Intent(context, TrainDetailActivity.class);
                intent.putExtra("t_id", t_id);
                context.startActivity(intent);
            }
        });
    }
}
